package com.example.store.service.impl;

import com.example.store.entity.Product;
import com.example.store.mapper.ProductMapper;
import com.example.store.service.IProductService;
import com.example.store.service.ex.ProductNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements IProductService {
    @Autowired
    private ProductMapper productMapper;
    @Override
    public List<Product> findHotList() {
        List<Product> data = productMapper.findHotList();
        return data;
    }

    @Override
    public Product findById(Integer id) {
        Product product = productMapper.findById(id);
        if(product==null || product.getStatus()==3){
            throw new ProductNotFoundException("商品数据不存在异常");
        }
        if(product.getStatus()==2){
            throw new ProductNotFoundException("商品已下架异常");
        }

        return product;
    }
}
